package com.aivin.tvslidebar.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

import com.aivin.tvslidebar.R;

import com.aivin.tvslidebar.scrool2.StringScrollPicker;

import java.util.ArrayList;
import java.util.List;


/**
 * https://blog.csdn.net/u012964944/article/details/73189206
 * @author ly-dengpw
 */
public class ScrollPickerViewDemo extends Activity {
    private StringScrollPicker scrollPicker;
    TextView tvResult ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scrollpickerview);
        tvResult = findViewById(R.id.tvResult);

        init();


        findViewById(R.id.btnTest).setOnClickListener(v -> scrollPicker.setSelectedPosition(3));
    }

    private void init() {
        scrollPicker = findViewById(R.id.picker_05_horizontal);
        List<String> list = new ArrayList<>();
        for (int i=0 ; i<=30 ;i++){
            list.add(String.valueOf(i));
        }

        scrollPicker.setData(list);
        scrollPicker.setSelectedPosition(0);
        scrollPicker.setOnSelectedListener((scrollPickerView, position ,value2) ->{
            String value = list.get(position);
            tvResult.setText("" + (position +" - "+ value +"  "+value2));
        });
    }


}
